package goods_manage.handler;

import goods_manage.entity.GoodsDo;
import goods_manage.service.GoodsService;
import goods_manage.service.impl.GoodsServiceImpl;
import goods_manage.show.MainView;
import goods_manage.show.view.UpdateGoodsView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UpdateGoodsViewHandler implements ActionListener {
    private UpdateGoodsView updateGoodsView;
    private MainView mainView;
    public UpdateGoodsViewHandler(UpdateGoodsView updateGoodsView, MainView mainView){
        this.updateGoodsView = updateGoodsView;
        this.mainView=mainView;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text=jButton.getText();
        if("修改".equals(text)){
            GoodsService goodsService =new GoodsServiceImpl();
            GoodsDo goodsDo = updateGoodsView.buildUpdateGoods();
            System.out.println("我是你爹");
            boolean updateResult= goodsService.update(goodsDo);
            if(updateResult){
                //更新表格数据
                mainView.reloadTable();
                updateGoodsView.dispose();
                JOptionPane.showMessageDialog(updateGoodsView,"修改成功");
            }else{
                JOptionPane.showMessageDialog(updateGoodsView,"修改失败");
            }
        }
    }
}
